import time

import allure

from base.base_page import BasePage
from pages import username_loc, password_loc, verify_code_loc, login_button_loc, success_text_loc, error_text_loc


def test_login_assert(data):
    username = data["username"]
    password = data["password"]
    verify_code = data["verify_code"]
    expected_error = data["expected_error"]


class PageLogin(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.__username_loc=username_loc  #用户名
        self.__password_loc=password_loc   #密码
        self.__verify_code_loc=verify_code_loc   #验证码
        self.__login_button_loc = login_button_loc  #登录按钮
        self.__success_text_loc=success_text_loc#登录成功文本
        self.__error_text_loc=error_text_loc#登录失败文本
#输入用户名
    @allure.step("1.输入用户名")
    def __input_username(self,username):
        # *self.username_loc  解包
        # self.__driver.find_element(*self.__username_loc).send_keys(username)
        self.input_value(self.__username_loc,username)
    #输入密码
    @allure.step("2.输入密码")
    def __input_password(self,password):
        # self.__driver.find_element(*self.__password_loc).send_keys(password)
        self.input_value(self.__password_loc,password)
    #输入验证码
    @allure.step("3.输入验证码")
    def __input_verify_code(self,verify_code):
        # self.__driver.find_element(*self.__verify_code_loc).send_keys(verify_code)
        self.input_value(self.__verify_code_loc,verify_code)
    #点击登录
    @allure.step("4.点击登录")
    def __click_login_button(self):
        # self.__driver.find_element(*self.__login_button_loc).click()
        self.click_element(self.__login_button_loc)
    #获取登录成功的文本信息
    @allure.step("5.获取登录成功的文本信息")
    def get_login_success_text(self):
        # time.sleep(2)
        # return self.__driver.find_element(*self.__success_text_loc).text
        return self.get_element_text(self.__success_text_loc)
    #获取登录失败的文本信息
    @allure.step("6.获取登录失败的文本信息")
    def get_login_error_text(self):
        # time.sleep(2)
        # return self.__driver.find_element(*self.__error_text_loc).text
        return self.get_element_text(self.__error_text_loc)

    def login(self,username,password,verify_code):
        self.__input_username(username)
        self.__input_password(password)
        self.__input_verify_code(verify_code)
        self.__click_login_button()
